package com.sky.greendao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import cn.lu.train.App;

public class DaoManager {

    private volatile static DaoManager manager = new DaoManager();
    private DaoSession daoSession;

    public static DaoManager getManager() {
        return manager;
    }

    public DaoSession getDaoSession() {
        return getDaoSession(App.get());
    }

    /**
     * 配置数据库
     */
    public DaoSession getDaoSession(Context context) {
        if (daoSession != null) {
            return daoSession;
        }
        //创建数据库shop.db
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, "chat.db", null);
        //获取可写数据库
        SQLiteDatabase db = helper.getWritableDatabase();
        //获取数据库对象
        DaoMaster daoMaster = new DaoMaster(db);
        //获取dao对象管理者
        daoSession = daoMaster.newSession();
        return daoSession;
    }

    public void closeHelper(){
    }

    public void closeDaoSession(){
    }
}
